<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>中心领导管理的操作页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
</head>
<body>
    <form class="layui-form" action="" id="Leader">
        <input type="hidden" name="leaderId" id="leaderId"/>
        <div class="layui-form-item"></div>
        <div class="layui-form-item">
            <label class="layui-form-label">领导名称</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="leaderName" id="leaderName" required
                       lay-verify="required" placeholder="领导名称" autocomplete="off"/>
            </div>
            <label class="layui-form-label">部门名称</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="deptName" id="deptName" required
                       lay-verify="required" placeholder="部门名称" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">岗位名称</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="postName" id="postName" required
                       lay-verify="required" placeholder="岗位名称" autocomplete="off"/>
            </div>
            <label class="layui-form-label">负责事务</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="leaderBusiness" id="leaderBusiness" required
                       lay-verify="required" placeholder="负责事务" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职责说明</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="leaderExp" id="leaderExp" required
                       lay-verify="required" placeholder="职责说明" autocomplete="off"/>
            </div>
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="phone" id="phone" required
                       lay-verify="required" placeholder="职责说明" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">通讯地址</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="addr" id="addr" required
                       lay-verify="required" placeholder="职责说明" autocomplete="off"/>
            </div>
            <label class="layui-form-label">其他说明</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="other" id="other" required
                       lay-verify="required" placeholder="其他说明" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn site-demo-active" lay-submit lay-filter="formDemo" >立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['form', 'layedit', 'laydate'], function() {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;
            //日期渲染
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });
            /**
            * 新增和修改
            */
            var form = null ;
            layui.use('form', function(){
                form = layui.form;
                //监听提交
                form.on('submit(formDemo)', function(data){
                    // 单击之后提交按钮不可选,防止重复提交
                    var DISABLED = 'layui-btn-disabled';
                    // 增加样式
                    $('.site-demo-active').addClass(DISABLED);
                    // 增加属性
                    $('.site-demo-active').attr('disabled', 'disabled');
                    var rolesId = "";
                    $("input[name='leaderId']:checked").each(function(index,item){

                        rolesId+=$(this).val()+",";

                    });
                    data.field.leaderId=rolesId;

                    //alert($("#leaderId").val()+"==============");
                    var formData = new FormData(document.getElementById("Leader"));
                    var url = "../../UserseControllerLeader/addAndUpdate";
                    $.ajax({
                        url:url,
                        type:"post",
                        data:formData,
                        processData:false,
                        contentType:false,
                        dataType:"json",
                        success:function(obj){
                            //alert("成功了");
                            layer.msg(obj.msg, {
                                icon: 1,
                                time: 1200 //1秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                //关闭当前层
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                //刷新父页面
                                parent.tableTwo.reload();

                                //重新渲染
                                form.render();
                            });
                        },
                        error:function(e){
                            layer.msg("操作错误!");
                        }
                    });
                    return false;
                });
                var id = getQueryString("id");
                if(id !="" && id != null){
                    findlx(id);
                }
            });
            /**
             * 修改显示
             */
            function findlx(){
                var id = getQueryString("id");
                //var username = document.getElementById("isva").value;
                //alert(username);
                if(id){
                    var url = "../../UserseControllerLeader/select";
                    var data = {leaderId:id};
                    //jquery的ajax方法,查询类型的方法
                    $.get(url,data,function(obj){
                        //从后台传过来的数据obj$("[value='11']").prop("checked",true);
                        $("#leaderId").val(obj.leaderId);
                        $("#leaderName").val(obj.leaderName);
                        $("#deptName").val(obj.deptName);
                        $("#postName").val(obj.postName);
                        $("#leaderBusiness").val(obj.leaderBusiness);
                        $("#leaderExp").val(obj.leaderExp);
                        $("#phone").val(obj.phone);
                        $("#addr").val(obj.addr);
                        $("#other").val(obj.other);
                        //重新渲染
                        form.render();
                    },"json");
                }

            }
        });

    </script>
</body>
</html>